package com.wxx.api;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MybatisPlusGenerator {
    // 生成Bean文件时文件头注释
    private static String author = "wxx";
    private static DbType db_type = DbType.MYSQL;
    private static String db_driver_name = "com.mysql.cj.jdbc.Driver";
    private static String db_user_name = "root";
    private static String db_password = "199410";
    private static String db_url= "jdbc:mysql://127.0.0.1:3306/im?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
    private static String[] tabs = new String[] {};     //只生成指定表的实体类
    private static String packageName = "com.wxx.api";

    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir("src\\main\\java");
        gc.setFileOverride(false);
        gc.setActiveRecord(true);
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(false);// XML columList
        gc.setAuthor(author);
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(db_type);
        dsc.setDriverName(db_driver_name);
        dsc.setUsername(db_user_name);
        dsc.setPassword(db_password);
        dsc.setUrl(db_url);
        mpg.setDataSource(dsc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        // strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
//        strategy.setTablePrefix(new String[]{});// 此处可以修改为您的表前缀
        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
        if (tabs.length > 0) {
            strategy.setInclude(tabs); // 将指定的表生成实体类
        }
        mpg.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent(packageName);
        mpg.setPackageInfo(pc);

        mpg.execute();
    }
}